﻿using System;
using System.IO;
using System.Drawing;

//自定义命名空间
using BasicUtility = DreamCube.Foundation.Basic.Utility;

namespace BGN.PlugIn.Client.Msg
{
    public class SinfoMsgPlugIn : SisenMESS_Interface.SisenMESS_Tools_Interface, SisenMESS_Interface.SisenMESS_Tools_Msg_Interface
    {
        public event SisenMESS_Interface.OnRequestSetFormLocationEventArgsHandler OnSetFormLocation;

        public event SisenMESS_Interface.OnRequestSetFormSizeEventArgsHandler OnSetFormSize;

        /// <summary>
        /// 标志模块是否已经打开
        /// </summary>
        private Boolean isLogined = false;

        /// <summary>
        /// 公司名称
        /// </summary>
        public string _Company
        {
            get { return SinfoMsgPlugInConfiger.Instance.GetCompanyName(); }
        }

        /// <summary>
        /// 插件ID号
        /// </summary>
        public string _ID
        {
            get { return SinfoMsgPlugInConfiger.Instance.GetID(); }
        }

        /// <summary>
        /// 插件图标
        /// </summary>
        public System.Drawing.Image _Icon
        {
            get
            {
                try
                {
                    String path = Path.Combine(BasicUtility.MyDll.GetCurrentDllPath(), SinfoMsgPlugInConfiger.Instance.GetIcon());
                    return Image.FromFile(path);
                }
                catch (Exception ex)
                {
                    BasicUtility.MyLog.MakeLog(ex);
                }
                return Properties.Resources.msg;
            }
        }

        /// <summary>
        /// 判断是否登录
        /// </summary>
        public bool _IsLogined
        {
            get { return false; }
            set { isLogined = false; }
        }

        /// <summary>
        /// 获取产品名称
        /// </summary>
        public string _Product
        {
            get { return SinfoMsgPlugInConfiger.Instance.GetProduct(); }
        }

        public string _ServerIp
        {
            get;
            set;
        }

        /// <summary>
        /// 加一个默认的构造函数，方便调试进来
        /// </summary>
        public SinfoMsgPlugIn()
        {
            RemotingService.Start();
        }

        /// <summary>
        /// 显示窗口的方法
        /// </summary>
        public void _Show()
        {
            
        }

        public string _UserId
        {
            get;
            set;
        }

        public string _UserName
        {
            get;
            set;
        }

        public string _UserNo
        {
            get;
            set;
        }

        public string _UserPassWord
        {
            get;
            set;
        }

        public event SisenMESS_Interface.OnGetUserListHandler OnGetUserList;

        public event SisenMESS_Interface.OnGetWorkGroupHandler OnGetWorkGroup;

        public event SisenMESS_Interface.OnOpenUserMsgFormEventArgsHandler OnOpenUserMsgForm;

        public event SisenMESS_Interface.OnSendEventArgsHandler OnSendDate;

        public bool _IsOnline
        {
            get;
            set;
        }

        /// <summary>
        /// 接收到数据后回调的方法；弹出电脑飘窗
        /// </summary>
        /// <param name="oj"></param>
        public void _ReceiveData(Object obj)
        {
            Byte[] data = obj as Byte[];
            if (data != null)
            {
                String msg = System.Text.Encoding.UTF8.GetString(data);
                if (String.IsNullOrEmpty(msg)) return;
                //{0}^|^{1}^|^{2}^|^{3}^|^{4}", 
                //MyNumber.ToInt(eMessageType), sMsgID, MyDateTime.FormatDateTime(CStr(Now())), sTempSender, sMsg
                //解析消息，获取消息的ID号
                String msgType = BasicUtility.MyString.Left(msg, "^|^"); //消息类型
                String tempMsgNoType = BasicUtility.MyString.Right(msg, "^|^");
                String msgID = BasicUtility.MyString.Left(tempMsgNoType, "^|^");  //消息ID号
                String tempMsgNoID = BasicUtility.MyString.Right(tempMsgNoType, "^|^");
                String msgSendDatetime = BasicUtility.MyString.Left(tempMsgNoID, "^|^");  //消息发出的时间日期
                String tempMsgNoSendDatetime = BasicUtility.MyString.Right(tempMsgNoID, "^|^");
                String sSender = BasicUtility.MyString.Left(tempMsgNoSendDatetime, "^|^");
                String msgHtmlFilePath = MsgHelper.SaveMsg(BasicUtility.MyString.Right(tempMsgNoSendDatetime, "^|^"), sSender, this._UserName, msgSendDatetime);
                ShowMsgForm form = new ShowMsgForm(msgID, msgHtmlFilePath, this._UserName, this._UserNo, this._UserPassWord);
                form.Show();
            }
        }

        public void _UpdateUserList(System.Data.DataTable userlist_dt)
        {
            
        }

        public void _UpdateWorkGroup(System.Data.DataTable workgroup_dt)
        {
            
        }

        public void _UserOnline(string userid, string user_online_type, string userip)
        {
            
        }

        public void _UserOutLine(string userid)
        {
            
        }
    }
}
